package it.uniroma2.art.owlart.model.syntax.manchester;

import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.exceptions.ModelUpdateException;
import it.uniroma2.art.owlart.model.ARTBNode;
import it.uniroma2.art.owlart.model.ARTURIResource;


public class Restriction {
	private String restriction;
	public OWLModel model;
	public ARTBNode resource;

	public Restriction(String r,Primary value,ARTURIResource uriRes,OWLModel mod) throws ModelAccessException, ModelUpdateException {
		restriction=r;
		//System.out.println("Restrizione: "+restriction);
		model=mod;


		ARTBNode res=model.createBNode();
		if(restriction.equals(" some ")) {
			model.addRestrictionOnPropertySomeValuesFrom(res.getID(), uriRes, value.resource);
			resource=res;
		}
		else {
			if(restriction.equals(" only ")) {

				model.addRestrictionOnPropertyAllValuesFrom(res.getID(), uriRes, value.resource);
				resource=res;
			}
		}
	}

	public Restriction(Uri u,ARTURIResource uriRes,OWLModel mod) throws ModelUpdateException, ModelAccessException {
	    	restriction="value";
		model=mod;
		
		ARTBNode res=model.createBNode();
		model.addRestrictionOnPropertyHasValue(res.getID(), uriRes, u.uriRes);

		resource=res;
	}

	public Restriction(ARTURIResource uriRes,OWLModel mod) throws ModelAccessException {
	   
		restriction="self";
		model= mod;


	}

	//ATTENZIONE non implementata come "quadrupla"..manca la definizione value..children min 3 Male
	public Restriction(String r,String num,Primary value,ARTURIResource uriRes,OWLModel mod) throws ModelAccessException, ModelUpdateException {
		restriction=r;
		model=mod;

		ARTBNode res=model.createBNode();
		if(restriction.equals(" min ")) {

			model.addRestrictionOnCardinalityMinCardinality(res.getID(), uriRes, num);
				//model.addRestrictionOnPropertySomeValuesFrom(res.getID(), uriRes, value.resource);
			
			resource=res;
		}
		else {
			if(restriction.equals(" max ")) {

				model.addRestrictionOnCardinalityMaxCardinality(res.getID(), uriRes, num);

				resource=res;
			}
			else {
				if(restriction.equals(" exactly ")) {

					model.addRestrictionOnCardinalityCardinality(res.getID(), uriRes, num);

					resource=res;
				}
			}
		}

	}

	public Restriction(String r,String num,ARTURIResource uriRes,OWLModel mod) throws ModelUpdateException, ModelAccessException {
		restriction=r;
		//card=Integer.parseInt(num);
		//System.out.println("Restrizione senza Primary: "+restriction+" "+num+" uriRes: "+uriRes.getURI());
		model=mod;

		ARTBNode res=model.createBNode();
		if(restriction.equals(" min ")) {
			model.addRestrictionOnCardinalityMinCardinality(res.getID(), uriRes, num);
			//model.addRestrictionOnPropertySomeValuesFrom(res.getID(), uriRes, value.resource);

			resource=res;
		}
		else {
			if(restriction.equals(" max ")) {

				model.addRestrictionOnCardinalityMaxCardinality(res.getID(), uriRes, num);

				resource=res;
			}
			else {
				if(restriction.equals(" exactly ")) {

					model.addRestrictionOnCardinalityCardinality(res.getID(), uriRes, num);

					resource=res;
				}
			}
		}
	}

}
